Tuesday, May 09, 2006

Shared Objects (Flash Cookies)

Here is the code to set up the shared object:
//HIGH SCORE SHARED OBJECT =======================================
// create a new shared object named "zionshighscore"
my_so = SharedObject.getLocal("zionshighscore");
// set a new variable (highScore) to 0
if (my_so.data.highScore == undefined) {
my_so.data.highScore = 0;
}
// this saves the shared object immediately as opposed to when the swf shuts down
my_so.flush;
//my_so.data.highScore = 0;
highScore_mc.highScore.text = "$"+my_so.data.highScore+".00";
// show or hide high score display
if (my_so.data.highScore == 0) {
highScore_mc._alpha = 0;
} else {
highScore_mc._alpha = 100;
}
zeroHighScore.onRelease = function() {
my_so.data.highScore = 0;
highScore_mc.highScore.text = "$"+my_so.data.highScore+".00";
};
//

This code sets the shared object to a new value:
updateHighScore = function () {
if (theScore>my_so.data.highScore) {
my_so.data.highScore = theScore;
showPrompt("New High Score!", 4000);
}
};

No comments: